package vn.sunnet.backviet01.game.coloa.util;

import java.util.StringTokenizer;

import org.anddev.andengine.opengl.texture.region.TextureRegion;

import vn.sunnet.backviet01.game.coloa.util.Contain.StateSkill;

public class SkillMenu extends MySprite{
	private int containBy = -1;
	
	private float damage;
	private float useMana;
	
	private boolean isMove = false;
	private StateSkill mState;
	
	private int limit = 0;
	private int level = 1;
	private int maxLevel = 1;
	
	private final int ID;
	private int condition = 0;
	
	private float coolDown = 1;
	private float delayEnemy = 0;
	
	public float nextManaUse = 0;
	public float nextTurn = 0;
	public float nextDamage = 0;
	public float nextDelayEnemy = 0;
	
	private String skillName;
	private String coolDownString = "";
	private String damageString = "";
	private String useManaString = "";
	private String delayEnemyString = "";

	public SkillMenu(int id, int ZIndex, float pX, float pY, TextureRegion pTextureRegion) {
		super(ZIndex, pX, pY, pTextureRegion);
		this.ID = id;
		
		resetInfomation();
	}
		
	public int getMaxLevel() {
		return maxLevel;
	}
	
	public int getContainBy() {
		return containBy;
	}

	public void setContainBy(int containBy) {
		this.containBy = containBy;
	}

	public float getDelayEnemy() {
		return delayEnemy;
	}

	public int getLevel() {
		return level;
	}

	public void setLevel(int level) {
		this.level = level;
		setDamage(level);
		setCoolDown(level);
		setUseMana(level);
		setDelayEnemy(level);
	}

	public void setDelayEnemy(float delayEnemy) {
		this.delayEnemy = delayEnemy;
	}

	public String getDelayEnemyString() {
		return delayEnemyString;
	}

	public void setDelayEnemyString(String delayEnemy) {
		this.delayEnemyString = delayEnemy;
	}

	public String getCoolDownString() {
		return coolDownString;
	}

	public void setCoolDownString(String coolDownString) {
		this.coolDownString = coolDownString;
	}

	public String getDamageString() {
		return damageString;
	}

	public void setDamageString(String damageString) {
		this.damageString = damageString;
	}

	public String getUseManaString() {
		return useManaString;
	}

	public void setUseManaString(String useManaString) {
		this.useManaString = useManaString;
	}

	public float getCoolDown() {
		return coolDown;
	}

	public void setCoolDown(float coolDown) {
		this.coolDown = coolDown;
	}
	
	public void setDelayEnemy(int level) {
		StringTokenizer stk = null;
		stk = new StringTokenizer(delayEnemyString, "/");
		
		int count = 1;
		int token = stk.countTokens();
		
		while(count < level && count < token) {
			count++;
			stk.nextToken();
		}
		delayEnemy = Float.valueOf(stk.nextToken());

		try {
			nextDelayEnemy = Float.valueOf(stk.nextToken());
		} catch (Exception e) {
			nextDelayEnemy = delayEnemy;
		}
	}
	
	public void setCoolDown(int level) {
		StringTokenizer stk = null;
		stk = new StringTokenizer(coolDownString, "/");
		
		int count = 1;
		int token = stk.countTokens();
		
		while(count < level && count < token) {
			count++;
			stk.nextToken();
		}
		coolDown = Float.valueOf(stk.nextToken());

		try {
			nextTurn = Float.valueOf(stk.nextToken());
		} catch (Exception e) {
			nextTurn = coolDown;
		}
	}
	
	public float nextDamage() {
		float damage = 0;
		StringTokenizer stk = null;
		stk = new StringTokenizer(damageString, "/");
		
		int token = stk.countTokens();
		
		if (level == token) {
			damage = this.damage;
		} else {
			int count = 1;
			while(count < level + 1 && count < token) {
				count++;
				stk.nextToken();
			}
			damage = Float.valueOf(stk.nextToken());
		}
					
		return damage;
	}
	
	public void setDamage(int level) {
		StringTokenizer stk = null;
		stk = new StringTokenizer(damageString, "/");
		
		int count = 1;
		int token = stk.countTokens();
		maxLevel = token;
		while(count < level && count < token) {
			count++;
			stk.nextToken();
		}
		damage = Float.valueOf(stk.nextToken());
		
		try {
			nextDamage = Float.valueOf(stk.nextToken());
		} catch (Exception e) {
			nextDamage = damage;
		}
	}
	
	public void setUseMana(int level) {
		StringTokenizer stk = null;
		stk = new StringTokenizer(useManaString, "/");
		
		int count = 1;
		
		int token = stk.countTokens();
		
		while(count < level && count < token) {
			count++;
			stk.nextToken();
		}
		useMana = Float.valueOf(stk.nextToken());
		
		try {
			nextManaUse = Float.valueOf(stk.nextToken());
		} catch (Exception e) {
			nextManaUse = useMana;
		}
		
	}
	
	public void setDelay(float delay) {
		this.delayEnemy = delay;
	}
	
	public float getDelay() {
		return delayEnemy;
	}
	
	public StateSkill getState() {
		return mState;
	}

	public void setState(boolean isActive) {
		if (isActive)
			mState = StateSkill.ACTIVE;
		else 
			mState = StateSkill.PASSIVE;
	}

	public void setName(final String name) {
		this.skillName = name;
	}
	
	public void setCondition(int condition) {
		this.condition = condition;
	}
	
	public int getCondition() {
		return condition;
	}
	
	public String getName() {
		return this.skillName;
	}
	
	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

	public boolean isMove() {
		return isMove;
	}

	public void setMove(boolean isMove) {
		this.isMove = isMove;
	}

	public int getID() {
		return ID;
	}

	public float getDamage() {
		return damage;
	}

	public void setDamage(float damage) {
		this.damage = damage;
	}

	public float getUseMana() {
		return useMana;
	}

	public void setUseMana(float useMana) {
		this.useMana = useMana;
	}

}
